#ifndef ARDUINOFIRMATA_HPP
#define ARDUINOFIRMATA_HPP

#include <talos/arduino/Arduino.hpp>
#include <talos/arduino/firmata.hpp>
#include <talos/utils/types.hpp>

#define MAX_QUERIES 8

namespace talos
{

	class ArduinoFirmata : public Arduino
	{
		public:

			ArduinoFirmata( const std::string serialPort, const int baudRate );

			/************
			 * EMISSION *
			 ************/

			/*{*/

			/*!
			 * \brief Query the version of the Firmware loaded in Arduino
			 *
			 * The response is return by the arduino via serial port.
			 */
			void queryFirmware();

			void setPWM( uint8_t pinNumber, uint16_t value );

			/*!
			 * \brief Set the analog pin to a new mode
			 * \param pinNumber the analog pin number
			 * \param state ANALOG_READ (read just one time)
			 *              ANALOG_READ_CONTINUOUSLY (read every sample period)
			 *              ANALOG_STOP_READING (stop continuous reading)
			 */
			void setAnalog( uint8_t pinNumber, uint16_t state );

			/*}*/

			/*************
			 * RECEPTION *
			 *************/

			/*{*/

			/*!
			 * \brief The way to process message from arduino.
			 */
			virtual void processMessage( std::string& message );

			/*!
			 * \brief What to do when protocol is received
			 */
			virtual void onProtocol( uint8_t major, uint8_t minor );

			/*!
			 * \brief What to do when firmware id is received
			 */
			virtual void onFirmware( std::string name, uint8_t major, uint8_t minor );

			/*!
			 * \brief What to do on message reception
			 */
			virtual void onMessage( std::string message );

			/*!
			 * \brief What to do on Analog pin value reception
			 */
			virtual void onAnalog( uint8_t pin, uint16_t value );

			/*}*/
	};

}

#endif // ARDUINOFIRMATA_HPP
